/*
 *  Copyright 2010 Mahbub Mozadded Sowrov.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package com.sowrov.afrigis.tools.timesheet;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * Write about the class here
 *
 * @author Mahbub Mozadded (Sowrov)
 * @date Apr 5, 2010
 */
public class Project {

    private String name;

    private String id;
    private String rate;

    private ArrayList<Activity> activityList;

    public Project() {
        this.name = "";
        this.id = "";
        this.rate = "";
        this.activityList = new ArrayList<Activity>();
    }

    /**
     * 
     * @param name name of the project
     * @param id_rate '/' separated id and rate, i.e. id/rate
     */
    public Project(String name, String id_rate){
        StringTokenizer strtok = new StringTokenizer(id_rate, "/");
        this.id = "";
        while (strtok.hasMoreTokens()) {
            if (this.id.equals("")) {
                this.id = strtok.nextToken();
            } else {
                this.rate = strtok.nextToken();
                break;
            }
        }
        this.name = name;
        this.activityList = new ArrayList<Activity>();
    }
    
    public Project(String name, String id, String rate) {
        this.name = name;
        this.id = id;
        this.rate = rate;
        this.activityList = new ArrayList<Activity>();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRate() {
        return rate;
    }

    public void setRate(String rate) {
        this.rate = rate;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addActivity(Activity activity) {
        this.activityList.add(activity);
    }

    public void clearActivity() {
        this.activityList.clear();
    }

    public int getActivityCount() {
        return this.activityList.size();
    }

    public Activity getActivityById(String aId) {
        Activity a = null;
        for (int i=0; i<this.activityList.size(); i++) {
            if (this.activityList.get(i).getId().equalsIgnoreCase(aId)) {
                a = this.activityList.get(i);
                break;
            }
        }
        return a;
    }

    public int getActivityIndexById(String aId) {
        int index = -1;
        for (int i=0; i<this.activityList.size(); i++) {
            if (this.activityList.get(i).getId().equalsIgnoreCase(aId)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public Activity getActivityByName(String aName) {
        Activity a = null;
        for (int i=0; i<this.activityList.size(); i++) {
            if (this.activityList.get(i).getName().equalsIgnoreCase(aName)) {
                a = this.activityList.get(i);
                break;
            }
        }
        return a;
    }

    public Activity getActivityAt(int i) {
        if (i >= this.activityList.size()) {
            return null;
        }
        return this.activityList.get(i);
    }
}
